package java67_adv3;

import java.util.*;

public class MapTEst {
	// get 是 null,containsKey返回false
	public static void main(String[] args) {
		// Map :无序,key不能重复,值可以重复
		Map map = new HashMap();
		map.put("dog", "狗");
		map.put("cow", "牛");
		map.put("cat", "猫");
		map.put("snake", "蛇");
		map.put("cow", "水牛");// 重复了,则覆盖
		map.put("貔貅", null);

		System.out.println(map.size());
		System.out.println(map);
		Scanner in = new Scanner(System.in);
		boolean c = map.containsKey("cow");
		System.out.println("cow是否存在?" + c);
		System.out.println("输入一个洋文 :");
		String key = in.next();
		if (map.containsKey(key)) {
			System.out.println("存在!");
			String value = (String) map.get(key);
			System.out.println(value);
		} else {
			System.out.println(key + "不存在");
		}
		System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
		Set keys = map.keySet();
		Collection con = map.values();
		System.out.println("所有的key:" + keys);
		System.out.println("所有的值:" + con);
		System.out.println(">>>>>>>>>>>>>遍历>>>>>>>>>>>>>>>>>>>>>>>");
		for (Object o : keys) {
			Object v = map.get(o);
			System.out.println(o + "=>>" + v);
		}
		// Entry
	}

}
